﻿using Lee.Models.Entities;
using Lee.Utility.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; 

namespace Lee.EF.ModelConfigurations
{
    internal class Biz_AdminConfiguration : IEntityTypeConfiguration<Biz_Admin>
    {
        public void Configure(EntityTypeBuilder<Biz_Admin> entity)
        {
            entity.HasKey(e => e.id).HasName("PRIMARY");
            entity.ToTable("Biz_Admin");
            entity.Property(x => x.id).ValueGeneratedOnAdd();//id自增
            entity.Property(x => x.name).HasMaxLength(50);
            entity.Property(x => x.password).HasMaxLength(20); 
            var entityType = typeof(Biz_Admin);
            if (typeof(ISoftDelete).IsAssignableFrom(entityType))
            {
                entity.HasQueryFilter(f => (f.isdeleted.HasValue && !f.isdeleted.Value) || (!f.isdeleted.HasValue));
            }

            //mock一条数据
            entity.HasData(new Biz_Admin()
            {
                id= 50,
                name = "lee",
                password = "123456",
                isdeleted= false,
            });
        }
    }
}
